.class public Lcom/noshufou/android/su/SuRequestReceiver;
.super Landroid/content/BroadcastReceiver;
.source "SuRequestReceiver.java"


# static fields
.field public static final EXTRA_ALLOW:Ljava/lang/String; = "allow"

.field public static final EXTRA_CALLERUID:Ljava/lang/String; = "caller_uid"

.field public static final EXTRA_CMD:Ljava/lang/String; = "desired_cmd"

.field public static final EXTRA_SOCKET:Ljava/lang/String; = "socket"

.field public static final EXTRA_UID:Ljava/lang/String; = "desired_uid"

.field public static final EXTRA_VERSION_CODE:Ljava/lang/String; = "version_code"

.field private static final TAG:Ljava/lang/String; = "Su.SuRequestReceiver"


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 51
    invoke-direct {p0}, Landroid/content/BroadcastReceiver;-><init>()V

    return-void
.end method

.method private sendResult(Landroid/content/Context;Landroid/content/Intent;Z)V
    .locals 6
    .parameter "context"
    .parameter "intent"
    .parameter "allow"

    .prologue
    .line 129
    new-instance v2, Landroid/net/LocalSocket;

    invoke-direct {v2}, Landroid/net/LocalSocket;-><init>()V

    .line 130
    .local v2, socket:Landroid/net/LocalSocket;
    const/4 v1, 0x0

    .line 132
    .local v1, os:Ljava/io/OutputStream;
    :try_start_0
    new-instance v3, Landroid/net/LocalSocketAddress;

    .line 133
    const-string v4, "socket"

    invoke-virtual {p2, v4}, Landroid/content/Intent;->getStringExtra(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    sget-object v5, Landroid/net/LocalSocketAddress$Namespace;->FILESYSTEM:Landroid/net/LocalSocketAddress$Namespace;

    invoke-direct {v3, v4, v5}, Landroid/net/LocalSocketAddress;-><init>(Ljava/lang/String;Landroid/net/LocalSocketAddress$Namespace;)V

    .line 132
    invoke-virtual {v2, v3}, Landroid/net/LocalSocket;->connect(Landroid/net/LocalSocketAddress;)V

    .line 134
    invoke-virtual {v2}, Landroid/net/LocalSocket;->getOutputStream()Ljava/io/OutputStream;

    move-result-object v1

    .line 135
    if-eqz p3, :cond_0

    const-string v3, "ALLOW"

    :goto_0
    invoke-virtual {v3}, Ljava/lang/String;->getBytes()[B

    move-result-object v3

    invoke-virtual {v1, v3}, Ljava/io/OutputStream;->write([B)V

    .line 136
    invoke-virtual {v1}, Ljava/io/OutputStream;->flush()V

    .line 137
    invoke-virtual {v1}, Ljava/io/OutputStream;->close()V

    .line 138
    invoke-virtual {v2}, Landroid/net/LocalSocket;->close()V

    .line 142
    :goto_1
    return-void

    .line 135
    :cond_0
    const-string v3, "DENY"
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 139
    :catch_0
    move-exception v0

    .line 140
    .local v0, e:Ljava/io/IOException;
    const-string v3, "Su.SuRequestReceiver"

    const-string v4, "Failed to write to socket"

    invoke-static {v3, v4, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_1
.end method

.method private showPrompt(Landroid/content/Context;Landroid/content/Intent;)V
    .locals 2
    .parameter "context"
    .parameter "intent"

    .prologue
    .line 122
    new-instance v0, Landroid/content/Intent;

    const-class v1, Lcom/noshufou/android/su/SuRequestActivity;

    invoke-direct {v0, p1, v1}, Landroid/content/Intent;-><init>(Landroid/content/Context;Ljava/lang/Class;)V

    .line 123
    .local v0, prompt:Landroid/content/Intent;
    invoke-virtual {v0, p2}, Landroid/content/Intent;->putExtras(Landroid/content/Intent;)Landroid/content/Intent;

    .line 124
    const/high16 v1, 0x1000

    invoke-virtual {v0, v1}, Landroid/content/Intent;->addFlags(I)Landroid/content/Intent;

    .line 125
    invoke-virtual {p1, v0}, Landroid/content/Context;->startActivity(Landroid/content/Intent;)V

    .line 126
    return-void
.end method


# virtual methods
.method public onReceive(Landroid/content/Context;Landroid/content/Intent;)V
    .locals 19
    .parameter "context"
    .parameter "intent"

    .prologue
    .line 63
    invoke-static/range {p1 .. p1}, Landroid/preference/PreferenceManager;->getDefaultSharedPreferences(Landroid/content/Context;)Landroid/content/SharedPreferences;

    move-result-object v12

    .line 64
    .local v12, prefs:Landroid/content/SharedPreferences;
    const-string v3, "pref_automatic_action"

    const-string v4, "prompt"

    invoke-interface {v12, v3, v4}, Landroid/content/SharedPreferences;->getString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v9

    .line 65
    .local v9, automaticAction:Ljava/lang/String;
    const-string v3, "deny"

    invoke-virtual {v9, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v3

    if-eqz v3, :cond_0

    .line 66
    const/4 v3, 0x0

    move-object/from16 v0, p0

    move-object/from16 v1, p1

    move-object/from16 v2, p2

    invoke-direct {v0, v1, v2, v3}, Lcom/noshufou/android/su/SuRequestReceiver;->sendResult(Landroid/content/Context;Landroid/content/Intent;Z)V

    .line 117
    :goto_0
    return-void

    .line 68
    :cond_0
    const-string v3, "allow"

    invoke-virtual {v9, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v3

    if-eqz v3, :cond_1

    .line 69
    const/4 v3, 0x1

    move-object/from16 v0, p0

    move-object/from16 v1, p1

    move-object/from16 v2, p2

    invoke-direct {v0, v1, v2, v3}, Lcom/noshufou/android/su/SuRequestReceiver;->sendResult(Landroid/content/Context;Landroid/content/Intent;Z)V

    goto :goto_0

    .line 72
    :cond_1
    const-string v3, "permissions_dirty"

    const/4 v4, 0x0

    invoke-interface {v12, v3, v4}, Landroid/content/SharedPreferences;->getBoolean(Ljava/lang/String;Z)Z

    move-result v3

    if-eqz v3, :cond_3

    .line 73
    const-string v3, "Su.SuRequestReceiver"

    const-string v4, "Database is dirty, check here"

    invoke-static {v3, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 74
    const-string v16, "uid=? AND exec_uid=? AND exec_cmd=?"

    .line 75
    .local v16, where:Ljava/lang/String;
    const-string v3, "Su.SuRequestReceiver"

    move-object/from16 v0, v16

    invoke-static {v3, v0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 76
    invoke-virtual/range {p1 .. p1}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

    move-result-object v3

    sget-object v4, Lcom/noshufou/android/su/provider/PermissionsProvider$Apps;->CONTENT_URI:Landroid/net/Uri;

    .line 77
    const/4 v5, 0x1

    new-array v5, v5, [Ljava/lang/String;

    const/4 v6, 0x0

    const-string v7, "allow"

    aput-object v7, v5, v6

    .line 78
    const-string v6, "uid=? AND exec_uid=? AND exec_cmd=?"

    .line 79
    const/4 v7, 0x3

    new-array v7, v7, [Ljava/lang/String;

    const/4 v8, 0x0

    const-string v17, "caller_uid"

    const/16 v18, -0x1

    move-object/from16 v0, p2

    move-object/from16 v1, v17

    move/from16 v2, v18

    invoke-virtual {v0, v1, v2}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I

    move-result v17

    invoke-static/range {v17 .. v17}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v17

    aput-object v17, v7, v8

    const/4 v8, 0x1

    .line 80
    const-string v17, "desired_uid"

    const/16 v18, -0x1

    move-object/from16 v0, p2

    move-object/from16 v1, v17

    move/from16 v2, v18

    invoke-virtual {v0, v1, v2}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I

    move-result v17

    invoke-static/range {v17 .. v17}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v17

    aput-object v17, v7, v8

    const/4 v8, 0x2

    .line 81
    const-string v17, "desired_cmd"

    move-object/from16 v0, p2

    move-object/from16 v1, v17

    invoke-virtual {v0, v1}, Landroid/content/Intent;->getStringExtra(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v17

    invoke-static/range {v17 .. v17}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v17

    aput-object v17, v7, v8

    const/4 v8, 0x0

    .line 76
    invoke-virtual/range {v3 .. v8}, Landroid/content/ContentResolver;->query(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v10

    .line 82
    .local v10, c:Landroid/database/Cursor;
    invoke-interface {v10}, Landroid/database/Cursor;->moveToFirst()Z

    move-result v3

    if-eqz v3, :cond_2

    .line 83
    const-string v3, "Su.SuRequestReceiver"

    const-string v4, "Found an entry"

    invoke-static {v3, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 84
    const/4 v3, 0x0

    invoke-interface {v10, v3}, Landroid/database/Cursor;->getInt(I)I

    move-result v3

    packed-switch v3, :pswitch_data_0

    .line 94
    const-string v3, "Su.SuRequestReceiver"

    const-string v4, "Prompt"

    invoke-static {v3, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 95
    invoke-direct/range {p0 .. p2}, Lcom/noshufou/android/su/SuRequestReceiver;->showPrompt(Landroid/content/Context;Landroid/content/Intent;)V

    .line 101
    :goto_1
    invoke-interface {v10}, Landroid/database/Cursor;->close()V

    goto/16 :goto_0

    .line 86
    :pswitch_0
    const-string v3, "Su.SuRequestReceiver"

    const-string v4, "Allow"

    invoke-static {v3, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 87
    const/4 v3, 0x1

    move-object/from16 v0, p0

    move-object/from16 v1, p1

    move-object/from16 v2, p2

    invoke-direct {v0, v1, v2, v3}, Lcom/noshufou/android/su/SuRequestReceiver;->sendResult(Landroid/content/Context;Landroid/content/Intent;Z)V

    goto :goto_1

    .line 90
    :pswitch_1
    const-string v3, "Su.SuRequestReceiver"

    const-string v4, "Deny"

    invoke-static {v3, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 91
    const/4 v3, 0x0

    move-object/from16 v0, p0

    move-object/from16 v1, p1

    move-object/from16 v2, p2

    invoke-direct {v0, v1, v2, v3}, Lcom/noshufou/android/su/SuRequestReceiver;->sendResult(Landroid/content/Context;Landroid/content/Intent;Z)V

    goto :goto_1

    .line 98
    :cond_2
    const-string v3, "Su.SuRequestReceiver"

    const-string v4, "No entry found, prompt"

    invoke-static {v3, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 99
    invoke-direct/range {p0 .. p2}, Lcom/noshufou/android/su/SuRequestReceiver;->showPrompt(Landroid/content/Context;Landroid/content/Intent;)V

    goto :goto_1

    .line 104
    .end local v10           #c:Landroid/database/Cursor;
    .end local v16           #where:Ljava/lang/String;
    :cond_3
    const-string v3, "pref_timeout"

    const/4 v4, 0x0

    invoke-interface {v12, v3, v4}, Landroid/content/SharedPreferences;->getInt(Ljava/lang/String;I)I

    move-result v13

    .line 105
    .local v13, sysTimeout:I
    if-lez v13, :cond_5

    .line 106
    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "active_"

    invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v4, "caller_uid"

    const/4 v5, 0x0

    move-object/from16 v0, p2

    invoke-virtual {v0, v4, v5}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I

    move-result v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v11

    .line 107
    .local v11, key:Ljava/lang/String;
    const-wide/16 v3, 0x0

    invoke-interface {v12, v11, v3, v4}, Landroid/content/SharedPreferences;->getLong(Ljava/lang/String;J)J

    move-result-wide v14

    .line 108
    .local v14, timeout:J
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v3

    cmp-long v3, v3, v14

    if-gez v3, :cond_4

    .line 109
    const/4 v3, 0x1

    move-object/from16 v0, p0

    move-object/from16 v1, p1

    move-object/from16 v2, p2

    invoke-direct {v0, v1, v2, v3}, Lcom/noshufou/android/su/SuRequestReceiver;->sendResult(Landroid/content/Context;Landroid/content/Intent;Z)V

    goto/16 :goto_0

    .line 112
    :cond_4
    invoke-direct/range {p0 .. p2}, Lcom/noshufou/android/su/SuRequestReceiver;->showPrompt(Landroid/content/Context;Landroid/content/Intent;)V

    goto/16 :goto_0

    .line 116
    .end local v11           #key:Ljava/lang/String;
    .end local v14           #timeout:J
    :cond_5
    invoke-direct/range {p0 .. p2}, Lcom/noshufou/android/su/SuRequestReceiver;->showPrompt(Landroid/content/Context;Landroid/content/Intent;)V

    goto/16 :goto_0

    .line 84
    :pswitch_data_0
    .packed-switch 0x0
        :pswitch_1
        :pswitch_0
    .end packed-switch
.end method
